package com.bustle.web.mbean.request;

import java.util.Date;
import java.util.List;
import java.util.Vector;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import com.bustle.product.ProductDtoManager;
import com.bustle.product.data.Product.ProductType;
import com.bustle.product.dto.product.ProductDto;

@ManagedBean
@RequestScoped
public class ProviderMBean
{
  public int getId()
  {
    return id;
  }

  public void setId(int anId)
  {
    id = anId;
    for (ProductDto product : productManager.getSearchProductProvider(anId))
    {
      productBeans.add(new ProductBean(product));
    }
  }

  public String getName()
  {
    return name;
  }

  public void setName(String aName)
  {
    name = aName;
  }

  public String getPhoneNumber()
  {
    return phoneNumber;
  }

  public void setPhoneNumber(String aPhoneNumber)
  {
    phoneNumber = aPhoneNumber;
  }

  public String getEmail()
  {
    return email;
  }

  public void setEmail(String anEmail)
  {
    email = anEmail;
  }

  public String getDescription()
  {
    return description;
  }

  public void setDescription(String aDescription)
  {
    description = aDescription;
  }

  public String getImage()
  {
    return image;
  }

  public void setImage(String aImage)
  {
    image = aImage;
  }

  public AddressBean getAddressBean()
  {
    return addressBean;
  }

  public void setAddressBean(AddressBean anAddressBean)
  {
    addressBean = anAddressBean;
  }

  public List<ProductBean> getProductBeans()
  {
    return productBeans;
  }

  private int id;
  private String name;
  private String phoneNumber;
  private String email;
  private String description;
  private String image;
  private AddressBean addressBean = new AddressBean();
  private final List<ProductBean> productBeans = new Vector<>();

  @EJB
  protected ProductDtoManager productManager;

  static public final String SCREEN = "partenaire.jsf";


  static public class AddressBean
  {
    public String getName()
    {
      return name;
    }

    public void setName(String aName)
    {
      name = aName;
    }

    public String getPostCode()
    {
      return postCode;
    }

    public void setPostCode(String aPostCode)
    {
      postCode = aPostCode;
    }

    public String getCity()
    {
      return city;
    }

    public void setCity(String aCity)
    {
      city = aCity;
    }

    protected String name;
    protected String postCode;
    protected String city;
  }

  static public class ProductBean
  {
    public ProductBean(ProductDto aProduct)
    {
      id = aProduct.getIdProduct();
      name = aProduct.getName();
      price = aProduct.getPrice();
      description = aProduct.getDescription();
      image = aProduct.getImage();
      creationDate = aProduct.getCreationDate();
      limitedDate = aProduct.getLimitedDate();
      type = aProduct.getProductType();
    }

    public String show()
    {
      return "article.jsf";
    }

    public int getId()
    {
      return id;
    }

    public void setId(int anId)
    {
      id = anId;
    }

    public String getName()
    {
      return name;
    }

    public void setName(String aName)
    {
      name = aName;
    }

    public double getPrice()
    {
      return price;
    }

    public void setPrice(double aPrice)
    {
      price = aPrice;
    }

    public String getDescription()
    {
      return description;
    }

    public void setDescription(String aDescription)
    {
      description = aDescription;
    }

    public String getImage()
    {
      return image;
    }

    public void setImage(String aImage)
    {
      image = aImage;
    }
    public Date getCreationDate()
    {
      return creationDate;
    }

    public void setCreationDate(Date aCreationDate)
    {
      creationDate = aCreationDate;
    }

    public Date getLimitedDate()
    {
      return limitedDate;
    }

    public void setLimitedDate(Date aLimitedDate)
    {
      limitedDate = aLimitedDate;
    }

    public ProductType getType()
    {
      return type;
    }

    public void setType(ProductType aType)
    {
      type = aType;
    }

    private int id;
    private ProductType type;
    private String name;
    private double price;
    private String description;
    private String image;
    private Date creationDate;
    private Date limitedDate;
  }
}
